

import java.awt.*;
import java.sql.SQLException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Stefano
 */
public class NuovoUtente extends javax.swing.JDialog {
    private final Frame parent2;
    int check1=0;
    int check2=0;
    int check3=0;
 
   
    private boolean ans=false;

    /**
     * Creates new form AnagraficaInserisci l'int sta per
     * 1=fornitore,2=cliente,3=agente
     */
    public NuovoUtente(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        parent2=parent;
        
        
        
        initComponents();
        Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
		this.setLocation(new Point(
				(dimension.width - this.getSize().width) / 2,
				(dimension.height - this.getSize().height) / 2));
        this.setLayout(new BorderLayout());
               this.nome.requestFocus();
                this.jCheckBox1.setSelected(true);
                this.jCheckBox2.setSelected(true);
                this.jCheckBox2.setEnabled(false);
                this.jCheckBox3.setSelected(true);
                this.jCheckBox3.setEnabled(false);
    }

    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pannelloInfo = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        nome = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jToggleButton3 = new javax.swing.JToggleButton();
        jToggleButton5 = new javax.swing.JToggleButton();
        jPanel3 = new javax.swing.JPanel();
        titolo = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        Salva = new javax.swing.JButton();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jPasswordField1 = new javax.swing.JPasswordField();
        jPasswordField2 = new javax.swing.JPasswordField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("inserisci anagrafica");

        pannelloInfo.setBackground(new java.awt.Color(255, 255, 255));
        pannelloInfo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel21.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jLabel21.setText("User");

        jLabel22.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jLabel22.setText("Ripeti password");

        jLabel23.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jLabel23.setText("Password");

        jToggleButton3.setToolTipText("Cerca Modello Base");
        jToggleButton3.setBorder(null);
        jToggleButton3.setContentAreaFilled(false);
        jToggleButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jToggleButton3MouseClicked(evt);
            }
        });

        jToggleButton5.setToolTipText("Cerca Linea");
        jToggleButton5.setBorder(null);
        jToggleButton5.setContentAreaFilled(false);
        jToggleButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jToggleButton5MouseClicked(evt);
            }
        });

        jPanel3.setBackground(new java.awt.Color(0, 51, 204));

        titolo.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        titolo.setForeground(new java.awt.Color(255, 255, 255));
        titolo.setText("Nuovo Utente");

        jPanel7.setBackground(new java.awt.Color(204, 204, 204));
        jPanel7.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        Salva.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Save.png"))); // NOI18N
        Salva.setToolTipText("Salva");
        Salva.setBorderPainted(false);
        Salva.setContentAreaFilled(false);
        Salva.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                SalvaMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(Salva, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(Salva)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titolo)
                .addContainerGap(285, Short.MAX_VALUE))
            .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(titolo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jCheckBox1.setText("Tutti i privilegi");
        jCheckBox1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jCheckBox1MouseClicked(evt);
            }
        });
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jCheckBox2.setText("Produzione");
        jCheckBox2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jCheckBox2MouseClicked(evt);
            }
        });

        jCheckBox3.setText("Commerciale");
        jCheckBox3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jCheckBox3MouseClicked(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout pannelloInfoLayout = new javax.swing.GroupLayout(pannelloInfo);
        pannelloInfo.setLayout(pannelloInfoLayout);
        pannelloInfoLayout.setHorizontalGroup(
            pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pannelloInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pannelloInfoLayout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(612, 612, 612)
                            .addComponent(jToggleButton5))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pannelloInfoLayout.createSequentialGroup()
                            .addGap(1074, 1074, 1074)
                            .addComponent(jToggleButton3)))
                    .addGroup(pannelloInfoLayout.createSequentialGroup()
                        .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel21)
                            .addComponent(jLabel23)
                            .addComponent(jLabel22))
                        .addGap(18, 18, 18)
                        .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(nome)
                            .addComponent(jPasswordField1)
                            .addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pannelloInfoLayout.createSequentialGroup()
                        .addComponent(jCheckBox1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBox2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBox3)))
                .addContainerGap())
            .addGroup(pannelloInfoLayout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        pannelloInfoLayout.setVerticalGroup(
            pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pannelloInfoLayout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel21))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox1)
                    .addComponent(jCheckBox2)
                    .addComponent(jCheckBox3))
                .addGap(13, 13, 13)
                .addGroup(pannelloInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jToggleButton5)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addComponent(jToggleButton3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pannelloInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 391, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pannelloInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    //modifica il titolo    
    public boolean risposta(){return ans;}
    
     public void Carica(String user,String pass, int priv ){
       this.nome.setText(user);
       this.jPasswordField1.setText(pass);
       this.jPasswordField2.setText(pass);
       switch(priv){
           case 1:this.jCheckBox1.setSelected(true);
                  this.jCheckBox2.setSelected(true);
                  this.jCheckBox2.setEnabled(false);
                  this.jCheckBox3.setSelected(true);
                  this.jCheckBox3.setEnabled(false);
               break;
           case 2:this.jCheckBox1.setSelected(false);
                  this.jCheckBox2.setSelected(true);
                  this.jCheckBox2.setEnabled(true);
                  this.jCheckBox3.setSelected(false);
                  this.jCheckBox3.setEnabled(true);
               break;
           case 3:this.jCheckBox1.setSelected(false);
                  this.jCheckBox2.setSelected(false);
                  this.jCheckBox2.setEnabled(true);
                  this.jCheckBox3.setSelected(true);
                  this.jCheckBox3.setEnabled(true);
               break;
           case 0:this.jCheckBox1.setSelected(false);
                  this.jCheckBox1.setEnabled(false);
                  this.jCheckBox2.setSelected(false);
                  this.jCheckBox2.setEnabled(false);
                  this.jCheckBox3.setSelected(false);
                  this.jCheckBox3.setEnabled(false);
               break;
       }
       
       
    }
    
    
    private void jToggleButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jToggleButton3MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton3MouseClicked

    private void jToggleButton5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jToggleButton5MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton5MouseClicked

    private void SalvaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SalvaMouseClicked
    Confermasalva cs = new Confermasalva(parent2,true);
    cs.setVisible(true);
   if (cs.risposta()) {if( this.jPasswordField1.getText().equals(this.jPasswordField2.getText())){
        int priv = 0;
        
        if (this.jCheckBox1.isSelected())check1=1;  
        if (this.jCheckBox2.isSelected())check2=1;  
        if (this.jCheckBox3.isSelected())check3=1;            
        switch(check1){
            case 1:priv=1;
            break;
            case 0:if(check2==1)priv=2;
                   if(check3==1)priv=3;
            break;    
                
        }
        
        
        this.registra(this.nome.getText(), this.jPasswordField1.getText(), priv);
        this.setVisible(false);
    }
    else{Errore er = new Errore(parent2,true);er.settitolo("Password non corrispondenti");
    er.setVisible(true);
    }// TODO add your handling code here://se la form di conferma e' ok 
       
    
       
       
       
       
       
       
     
   }
       // TODO add your handling code here:
    }//GEN-LAST:event_SalvaMouseClicked

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
         // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jCheckBox1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jCheckBox1MouseClicked
     if (!this.jCheckBox1.isSelected()){
          this.jCheckBox2.setEnabled(true);
          this.jCheckBox3.setEnabled(true);
          this.jCheckBox3.setSelected(false);
     }
     else {
         this.jCheckBox2.setSelected(true);
         this.jCheckBox2.setEnabled(false);
         this.jCheckBox3.setSelected(true);
         this.jCheckBox3.setEnabled(false);
     }
     
    }//GEN-LAST:event_jCheckBox1MouseClicked

    private void jCheckBox2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jCheckBox2MouseClicked
        if (this.jCheckBox2.isSelected()){
          this.jCheckBox3.setSelected(false);
       }
        else this.jCheckBox3.setSelected(true);
    }//GEN-LAST:event_jCheckBox2MouseClicked

    private void jCheckBox3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jCheckBox3MouseClicked
        if (this.jCheckBox3.isSelected()){
          this.jCheckBox2.setSelected(false);
       }
        else this.jCheckBox2.setSelected(true);
    }//GEN-LAST:event_jCheckBox3MouseClicked

   
            
            
    /**
     * @param args the command line arguments
     */ 
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Salva;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JPasswordField jPasswordField2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JToggleButton jToggleButton3;
    private javax.swing.JToggleButton jToggleButton5;
    private javax.swing.JTextField nome;
    private javax.swing.JPanel pannelloInfo;
    private javax.swing.JLabel titolo;
    // End of variables declaration//GEN-END:variables

   

    private static Boolean registra(java.lang.String utente, java.lang.String pass, int tipo) {
        gruppo12.LoginService_Service service = new gruppo12.LoginService_Service();
        gruppo12.LoginService port = service.getLoginServicePort();
        return port.registra(utente, pass, tipo);
    }

    
}
